package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcUtil 
{	
	static
	{
		String Driver = "com.mysql.jdbc.Driver";
		try {
			Class.forName(Driver);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	public static Connection getConnection()
	{
		String url = "jdbc:mysql://localhost:3306/qypwork";
		String usrNam = "root";
		String psw = "qyp199312";
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(url,usrNam,psw);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	public static void release(Connection conn,Statement s,ResultSet rs)
	{
		try
		{
			if(conn!=null)
				conn.close();
			if(s!=null)
				s.close();
			if(rs!=null)
				rs.close();
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
	}
	public static void release(Object o)
	{
		try {
			if(o instanceof Connection)
				((Connection) o).close();
			else if(o instanceof Statement)
				((Statement) o).close();
			if(o instanceof ResultSet)
				((ResultSet) o).close();
		}catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
